# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>

pkgname=golang-github-linuxdeepin-go-gir
pkgver=2.2.0
pkgrel=1
pkgdesc='Generate static golang bindings for GObject'
arch=('any')
url="https://github.com/linuxdeepin/go-gir-generator"
license=('GPL3')
depends=('gtk3' 'libgudev')
makedepends=('go' 'gobject-introspection')
checkdepends=('golang-gopkg-check.v1')
provides=('golang-deepin-gir')
conflicts=('golang-deepin-gir')
replaces=('golang-deepin-gir')
source=("$pkgname-$pkgver.tar.gz::https://github.com/linuxdeepin/go-gir-generator/archive/$pkgver.tar.gz")
sha512sums=('bf860d3c0235c3f0e5f334c415d7b4942290d4ae920ccbc25d7a1e4695c4a28450770c5ed9cecd127eff9163f67c2286120e2cf6d3fd2fc3e154f3db494ca746')

export GO111MODULE=off

prepare() {
  mkdir -p build/src/github.com/linuxdeepin

  # https://github.com/linuxdeepin/developer-center/issues/955
  sed -i "s/'Can'tFind'/“Can'tFind”/" go-gir-generator-$pkgver/lib.in/glib-2.0/keyfile_test.go
}

build() {
  export GOPATH="$srcdir/build:/usr/share/gocode"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"

  cd go-gir-generator-$pkgver
  rm -r gogtk-demo
  make

  mv out/src/github.com/linuxdeepin/go-gir "$srcdir"/build/src/github.com/linuxdeepin/
}

check() {
  export GOPATH="$srcdir/build:/usr/share/gocode"
  cd "$srcdir"/build/src/github.com/linuxdeepin/go-gir
  go test -v $(go list ./...)

  cd "$srcdir"/go-gir-generator-$pkgver
  go run test/memory.go
}

package() {
  mkdir -p "$pkgdir"/usr/share/gocode/src/github.com/linuxdeepin
  cp -a "$srcdir"/build/src/github.com/linuxdeepin/go-gir "$pkgdir"/usr/share/gocode/src/github.com/linuxdeepin/
}
